<template>
  <van-collapse-item 
    :name="account.id"
  >
    <template #title>
      <div class="account-header">
        <div class="account-icon" :style="{ backgroundColor: '#1989fa' }">
          {{ account.icon.substring(0, 3).toUpperCase() }}
        </div> 
        <div class="account-info">
          <!-- <span class="account-name">{{ account.icon }}</span> -->
          <span class="account-balance">{{ formatNumber(account.balance) }}</span>
        </div>
      </div>
    </template>
    
    <div class="account-details">
      <div class="balance-info">
        <div class="balance-item" @click="onViewTransactions">
          <span class="balance-label">可用余额</span>
          <span class="balance-value clickable">{{ formatNumber(account.balance) }} {{ account.icon }}</span>
        </div>
        <div class="balance-item" @click="onViewTransactions">
          <span class="balance-label">冻结金额</span>
          <span class="balance-value clickable">{{ formatNumber(account.frozen) }} {{ account.icon }}</span>
        </div>
      </div>
      
      <div class="account-actions">
        <van-button 
          v-if="showDeposit"
          type="primary" 
          block 
          @click="onDeposit"
        >
          充值
        </van-button>
        <van-button 
          v-if="showWithdraw"
          plain 
          type="success" 
          block 
          @click="onWithdraw"
        >
          提现
        </van-button>
      </div>
      
      <!-- 交易记录 -->
      <!-- <div class="transactions-header">
        <h3>交易记录</h3>
        <div class="view-all" @click="onViewTransactions">
          <span>查看全部</span>
          <van-icon name="arrow" />
        </div>
      </div>
      
      <div class="transactions-list">
        <TransactionItem
          v-for="tx in transactions" 
          :key="tx.id"
          :transaction="tx"
        />
        
        <van-empty v-if="transactions.length === 0" description="暂无交易记录" />
      </div> -->
    </div>
  </van-collapse-item>
</template>

<script setup>
import TransactionItem from './TransactionItem.vue'
import { formatNumber } from '@/utils/utils'

const props = defineProps({
  account: {
    type: Object,
    required: true
  },
  transactions: {
    type: Array,
    default: () => []
  },
  showDeposit: {
    type: Boolean,
    default: true
  },
  showWithdraw: {
    type: Boolean,
    default: true
  }
})

const emit = defineEmits(['deposit', 'withdraw', 'view-transactions'])

const onDeposit = () => {
  emit('deposit', props.account.name)
}

const onWithdraw = () => {
  emit('withdraw', props.account.name)
}

const onViewTransactions = () => {
  emit('view-transactions', props.account.name)
}
</script>

<style scoped>
.account-header {
  display: flex;
  align-items: center;
  padding: 12px 0;
}

.account-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
  font-size: 16px;
  font-weight: bold;
  color: white;
  text-transform: uppercase;
  box-shadow: 0 2px 8px rgba(25, 137, 250, 0.5);
  background-image: linear-gradient(135deg, #1989fa, #0066cc);
  letter-spacing: 0.5px;
  transition: all 0.3s ease;
}

.account-icon:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(25, 137, 250, 0.6);
}

.account-info {
  display: flex;
  flex-direction: column;
}

.account-name {
  font-size: 14px;
  color: var(--text-color);
}

.account-balance {
  font-size: 18px;
  font-weight: bold;
  color: #333;
  margin-top: 4px;
}

.account-details {
  padding: 16px;
}

.balance-info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
  background-color: #f8f9fa;
  border-radius: 12px;
  padding: 16px;
}

.balance-item {
  display: flex;
  flex-direction: column;
}

.balance-label {
  font-size: 13px;
  color: #666;
  margin-bottom: 6px;
}

.balance-value {
  font-size: 17px;
  font-weight: 600;
  color: #333;
}

.clickable {
  cursor: pointer;
  position: relative;
}

.clickable:after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 1px;
  background-color: #1989fa;
  transform: scaleX(0);
  transition: transform 0.3s ease;
}

.clickable:hover {
  color: #1989fa;
}

.clickable:hover:after {
  transform: scaleX(1);
}

.account-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.account-actions .van-button {
  height: 40px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  transition: all 0.3s ease;
}

.account-actions .van-button--primary {
  background: linear-gradient(135deg, #1989fa, #0066cc);
  border: none;
  box-shadow: 0 2px 6px rgba(25, 137, 250, 0.4);
}

.account-actions .van-button--plain {
  border: 1px solid #07c160;
  color: #07c160;
  background-color: rgba(7, 193, 96, 0.05);
}

.account-actions .van-button:active {
  transform: scale(0.98);
}

.transactions-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  margin-top: 16px;
}

.transactions-header h3 {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-color);
}

.transactions-list {
  margin-top: 8px;
}

.view-all {
  display: flex;
  align-items: center;
  color: var(--primary-color);
  font-size: 14px;
}

.view-all .van-icon {
  margin-left: 4px;
}
</style>